﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Widgetsphere.WebUtils;
using Widgetsphere.Autos.Websitev2.Objects;
using Widgetsphere.Autos.API.FacetedNavigation;

namespace Widgetsphere.Autos.Websitev2
{
    public partial class auto_make_results : BasePage
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            this.Populate();
        }

        private void Populate()
        {
            var url = new URL(this.Request.Url.AbsoluteUri);
            var query = new ListingQuery();
            var make = url.Parameters.GetValue("make");
            if (string.IsNullOrEmpty(make))
            {
                //TODO: SHOW ERROR
            }
            else
            {
                var rItem = RepositoryHelper.MasterResults.AllDimensions.MakeDimension.RefinementList.FirstOrDefault(x => x.FieldValue == make);
                if (rItem == null)
                {
                    //TODO: SHOW ERROR
                    return;
                }

                query.DimensionValueList.Add(rItem.DVIdx);
                var results = RepositoryHelper.Query(query);
                ModelDimensionControl1.Populate(results.AllDimensions.ModelDimension, false);
            }
        }

    }
}